package com.zou.study.springmvc;

import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;

public class WebAppTests {

    public static void main1(String[] args) {

//        WebApplicationInitializer.class;

        try (final AnnotationConfigReactiveWebApplicationContext ctx = new AnnotationConfigReactiveWebApplicationContext()) {
        }

    }

    public static void main(String[] args) throws LifecycleException {
        // org.springframework.boot.web.embedded.tomcat.TomcatWebServer
        final Tomcat tomcat = new Tomcat();

        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            System.out.println("开始停止tomcat容器！");
            try {
                tomcat.stop();
            } catch (LifecycleException e) {
                e.printStackTrace();
            }
            try {
                tomcat.destroy();
            } catch (LifecycleException e) {
                e.printStackTrace();
            }
        }));

        tomcat.setPort(8848);
        tomcat.setBaseDir(".");
//        tomcat.addWebapp("/", System.getProperty("user.dir") + "/src/main");
        tomcat.addContext("/tomcat", System.getProperty("user.dir") + "/src/main");

        System.out.println("开始启动tomcat容器！");
        tomcat.start();
        tomcat.getServer().await();
    }

}
